package org.mycub.server.requester.descriptors;

import java.net.URL;
import java.text.ParseException;
import java.util.concurrent.TimeUnit;

import org.geotools.data.Query;
import org.geotools.factory.CommonFactoryFinder;
import org.opengis.filter.FilterFactory;

public abstract class LayerDescription {

	private long timeToRefresh;
	private String typeName;
	private Query query;
	private FilterFactory filterFactory;
	private URL jsonURL;

	public LayerDescription(){
		filterFactory = CommonFactoryFinder.getFilterFactory( null ); 
	}

	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public Query getQuery() {
		return query;
	}

	public void setQuery(Query query) {
		this.query = query;
	}


	public FilterFactory getFilterFactory() {
		return filterFactory;
	}


	public void setFilterFactory(FilterFactory filterFactory) {
		this.filterFactory = filterFactory;
	}

	public URL getJsonURL() {
		return jsonURL;
	}

	public void setJsonURL(URL jsonURL) {
		this.jsonURL = jsonURL;
	}

	public long getTimeToRefresh() {
		return timeToRefresh;
	}

	public void setTimeToRefresh(long timeToRefresh) {
		this.timeToRefresh = timeToRefresh;
	}
	
	public void setTimeToRefresh(int days, int hours, int minutes){
		try {
			this.timeToRefresh = formatDate(days, hours, minutes);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	public long formatDate(int days, int hours, int minutes) throws ParseException{
		long daysConverted = TimeUnit.MILLISECONDS.convert(days, TimeUnit.DAYS);
		long hoursConverted = TimeUnit.MILLISECONDS.convert(hours, TimeUnit.HOURS);
		long minsConverted = TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES);
		
		return daysConverted + hoursConverted + minsConverted;
	}

}
